﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class SelfDebug : SingletonBehaviour<SelfDebug>
{
    public Text content;

    private void Start()
    {
        Application.logMessageReceived += (HandleLog);
    }

    void HandleLog(string logString, string stackTrace, LogType type)
    {
        string color = string.Empty;
        if (type == LogType.Error || type == LogType.Exception)//|| type == LogType.Log || type == LogType.Warning)
        {
            color = @"<color=#ff0000ff>{0}</color>";
        }
        else if (type == LogType.Log)
        {
            color = @"<color=#ffffffff>{0}</color>";
        }
        else if (type == LogType.Warning)
        {
            color = @"<color=#ffff00ff>{0}</color>";
        }

        content.text += string.Format(color, " Time: " + DateTime.Now.ToString() + " " + logString + stackTrace + "\n");

        this.GetComponent<ScrollRect>().verticalNormalizedPosition = 0.0f;
    }
    public override void Awake()
    {
        content.text = string.Empty;
    }
    public void LoggError(string  err)
    {
        content.text += err + "\n";
    }
    public void Log(string err)
    {
        content.text += err + "\n";
    }
    public void LogWarning(string err)
    {
        content.text += err + "\n";
    }
}
